# coding:utf-8
# writingtime: 
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pymysql
import time


def f(IVq_ROF, q):
    '''
    :param IVq_ROF: 广义正交数
    :param q:
     :return:
    '''
    a = IVq_ROF[0][0] ** q
    b = IVq_ROF[0][1] ** q
    c = IVq_ROF[1][0] ** q
    d = IVq_ROF[1][1] ** q
    score = ((abs(a - c) ** (1 / q) + abs(b - d) ** (1 / q)) / 2) + 1
    # Accaurate=(b-a)**(1/q)+(d-c)**(1/q)
    return (score / 2)


if __name__ == "__main__":
    print()
    ivq_dict = {'ud': [.1, .2], 'uu': [.1, .4], 'vd': [.5, .6], 'vu': [.7, .8]}
    vq_dict = {'ud': [.1, .5], 'uu': [.6, .4], 'vd': [0, .6], 'vu': [.7, .8]}
    data1 = pd.DataFrame(ivq_dict)
    data2 = pd.DataFrame(vq_dict)
    print(pd.concat([data1, data2], axis=0, ignore_index=True))
    a=(pd.DataFrame())
    print(pd.concat([a, data2], axis=0, ignore_index=True))
    from scoreFunction import getScore

    # print(getScore(np.array(data)[:,0],np.array(data)[:,1],np.array(data)[:,2],np.array(data)[:,3]))
    # print(np.array(data)[:,0])

    # print(data)
    # data.to_csv('text.csv',index=False, header=False)
    # pd.DataFrame(ivq_dict).to_csv('text.csv',index=False, header=False)
    # pd.DataFrame(vq_dict).to_csv('text.csv', mode='a', index=False, header=False)

    # data = pd.read_csv(r'data/case1/1.csv', names=["ur", "ul", "vr", "vl"], encoding='utf-8')
    # with pd.option_context('expand_frame_repr', False, 'display.max_rows', 15):
    #     print(data)
    # print(data)
    # a=data['ur']+data['ul']+data['vr']+data['vl']
    # print(a.value_counts())
    data = pd.read_csv('text.csv', names=["ur", "ul", "vr", "vl"], encoding='utf-8')
    # print(data.__len__())
    data['score']=(f(([data['ur'],data['ul']],[data['vr'],data['vl']]),4))
    # pd.DataFrame(data).to_csv('text.csv', index=False, header=False)
    # f2 = pd.read_csv(r'data/case2/2.csv', names=["ur", "ul", "vr", "vl", 'score'])
    # print(f1,'\n')
    # print(f2)
    # c=pd.concat([f1,f2],ignore_index=True)['score'].value_counts()
    # data=pd.DataFrame(ivq_dict)
    # print(list(data['uu']))
    # tt=set({})
    # tt.update(list(data['uu']))
    # tt.update(list(data['ud']))
    # print(tt)
    # pymysql
    # db = pymysql.connect(host='localhost',
    #                      user='root',
    #                      password='12345')
    # cursor = db.cursor()
    # sql='show databases'
    # print(cursor.execute(sql))
    # db.close()
    # temp = np.arange(0, 1, 0.1)
    # print(list(temp))
    # 列表解析式
    # print([j for j in list(temp) for i in range(10)])
    # print([i for j in range(10) for i in list(temp)])
    # b=[0,1,2]
    # print(b[1],b[-1])
    # print(int(bool(max(0,22))))
    # print(-2//2)
    # numpy
    # data=np.array()
    # d=np.array([1,1,-2,3])
    # c=np.array([1,2,3,4])
    # print(d*c)
    # print(d/abs(d))
